package com.heima.hoteldemo.controller;

import com.heima.hoteldemo.pojo.PageResult;
import com.heima.hoteldemo.pojo.RequestParams;
import com.heima.hoteldemo.service.IHotelService;
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author li
 */
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private IHotelService hotelService;

    /**
     * 案例1
     */
    @PostMapping("/list")
    public PageResult search(@RequestBody RequestParams params) {
        return hotelService.search(params);
    }

    /**
     * 得到过滤条件
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) {
        return hotelService.filters(params);
    }

    /**
     * 自动补全
     */
    @GetMapping("/suggestion")
    public List<String> suggestions(@RequestParam("key") String prefix) {
        return hotelService.suggestions(prefix);
    }

}
